package com.hzhr.iot.user.dao;

import com.hzhr.iot.user.dao.mapper.custom.DeptEntityCustomMapper;
import com.hzhr.iot.user.dao.mapper.generator.DeptEntityMapper;
import com.hzhr.iot.user.entity.DeptEntity;
import com.hzhr.iot.user.entity.ext.DeptEntityExt;
import com.hzhr.iot.user.queryModel.custom.DeptCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class DeptDao {
    @Autowired
    DeptEntityMapper deptEntityMapper;
    @Autowired
    DeptEntityCustomMapper deptEntityCustomMapper;

    public int insert(DeptEntity record) {
        if (record == null) return 0;
        int changeCount = deptEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = deptEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(DeptEntity record) {
        if (record == null) return 0;
        int changeCount = deptEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = deptEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public DeptEntity selectEntity(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeptEntityExt> extList = deptEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<DeptEntity> selectEntityList(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeptEntityExt> extList = deptEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<DeptEntity> entityList = new ArrayList<>();
        for (DeptEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public DeptEntityExt selectExt(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeptEntityExt> extList = deptEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<DeptEntityExt> selectExtList(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeptEntityExt> extList = deptEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public DeptEntity selectNameEntity(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeptEntityExt> extList = deptEntityCustomMapper.selectName(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<DeptEntity> selectNameEntityList(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeptEntityExt> extList = deptEntityCustomMapper.selectName(queryModel);
        if (extList == null) return null;
        List<DeptEntity> entityList = new ArrayList<>();
        for (DeptEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public DeptEntityExt selectNameExt(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeptEntityExt> extList = deptEntityCustomMapper.selectName(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<DeptEntityExt> selectNameExtList(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeptEntityExt> extList = deptEntityCustomMapper.selectName(queryModel);
        return extList;
    }



    public int selectCount(DeptCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = deptEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
